﻿USE [EventScavenger]
GO
CREATE TABLE [dbo].[PollFilters](
	[PollFilterID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
	[MessageContains] [nvarchar](1024) NULL,
	[LastChanged] [datetime] NOT NULL,
	[ExcludeInfo] [bit] NOT NULL,
	[ExcludeWarn] [bit] NOT NULL,
	[ExcludeErr] [bit] NOT NULL,
	[ExcludeSucAud] [bit] NOT NULL,
	[ExcludeFailAud] [bit] NOT NULL,
 CONSTRAINT [PK_PollFilters] PRIMARY KEY CLUSTERED 
(
	[PollFilterID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[PollFilterSources](
	[PollFilterID] [int] NOT NULL,
	[SourceID] [int] NOT NULL,
	[Exclude] [bit] NOT NULL,
 CONSTRAINT [PK_PollFilterSources] PRIMARY KEY CLUSTERED 
(
	[PollFilterID] ASC,
	[SourceID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[PollFilterEventIDs](
	[PollFilterID] [int] NOT NULL,
	[EventID] [int] NOT NULL,
	[Exclude] [bit] NOT NULL,
 CONSTRAINT [PK_PollFilterEventIDs] PRIMARY KEY CLUSTERED 
(
	[PollFilterID] ASC,
	[EventID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE dbo.MachineLogs ADD
	PollFilterID int NULL
GO

/****** Object:  Default [DF_PollFilterEventIDs_Exclude]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilterEventIDs] ADD  CONSTRAINT [DF_PollFilterEventIDs_Exclude]  DEFAULT ((0)) FOR [Exclude]
GO
/****** Object:  Default [DF_PollFilters_LastChanged]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilters] ADD  CONSTRAINT [DF_PollFilters_LastChanged]  DEFAULT (getdate()) FOR [LastChanged]
GO
/****** Object:  Default [DF_PollFilters_ExcludeInfo]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilters] ADD  CONSTRAINT [DF_PollFilters_ExcludeInfo]  DEFAULT ((0)) FOR [ExcludeInfo]
GO
/****** Object:  Default [DF_PollFilters_ExcludeWarn]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilters] ADD  CONSTRAINT [DF_PollFilters_ExcludeWarn]  DEFAULT ((0)) FOR [ExcludeWarn]
GO
/****** Object:  Default [DF_PollFilters_ExcludeErr]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilters] ADD  CONSTRAINT [DF_PollFilters_ExcludeErr]  DEFAULT ((0)) FOR [ExcludeErr]
GO
/****** Object:  Default [DF_PollFilters_ExcludeSucAud]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilters] ADD  CONSTRAINT [DF_PollFilters_ExcludeSucAud]  DEFAULT ((0)) FOR [ExcludeSucAud]
GO
/****** Object:  Default [DF_PollFilters_ExcludeFailAud]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilters] ADD  CONSTRAINT [DF_PollFilters_ExcludeFailAud]  DEFAULT ((0)) FOR [ExcludeFailAud]
GO
/****** Object:  Default [DF_PollFilterSources_Exclude]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilterSources] ADD  CONSTRAINT [DF_PollFilterSources_Exclude]  DEFAULT ((0)) FOR [Exclude]
GO
/****** Object:  ForeignKey [FK_MachineLogs_PollFilters]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[MachineLogs]  WITH CHECK ADD  CONSTRAINT [FK_MachineLogs_PollFilters] FOREIGN KEY([PollFilterID])
REFERENCES [dbo].[PollFilters] ([PollFilterID])
GO
/****** Object:  ForeignKey [FK_PollFilterEventIDs_EventIDs]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilterEventIDs]  WITH CHECK ADD  CONSTRAINT [FK_PollFilterEventIDs_EventIDs] FOREIGN KEY([EventID])
REFERENCES [dbo].[EventIDs] ([EventID])
GO
ALTER TABLE [dbo].[PollFilterEventIDs] CHECK CONSTRAINT [FK_PollFilterEventIDs_EventIDs]
GO
/****** Object:  ForeignKey [FK_PollFilterEventIDs_PollFilters]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilterEventIDs]  WITH CHECK ADD  CONSTRAINT [FK_PollFilterEventIDs_PollFilters] FOREIGN KEY([PollFilterID])
REFERENCES [dbo].[PollFilters] ([PollFilterID])
GO
ALTER TABLE [dbo].[PollFilterEventIDs] CHECK CONSTRAINT [FK_PollFilterEventIDs_PollFilters]
GO
/****** Object:  ForeignKey [FK_PollFilterSources_EventSources]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilterSources]  WITH CHECK ADD  CONSTRAINT [FK_PollFilterSources_EventSources] FOREIGN KEY([SourceID])
REFERENCES [dbo].[EventSources] ([SourceID])
GO
ALTER TABLE [dbo].[PollFilterSources] CHECK CONSTRAINT [FK_PollFilterSources_EventSources]
GO
/****** Object:  ForeignKey [FK_PollFilterSources_PollFilters]    Script Date: 07/02/2010 13:36:17 ******/
ALTER TABLE [dbo].[PollFilterSources]  WITH CHECK ADD  CONSTRAINT [FK_PollFilterSources_PollFilters] FOREIGN KEY([PollFilterID])
REFERENCES [dbo].[PollFilters] ([PollFilterID])
GO
ALTER TABLE [dbo].[PollFilterSources] CHECK CONSTRAINT [FK_PollFilterSources_PollFilters]
GO

Update Settings SET SettingValue = '3.4' WHERE SettingName like 'DatabaseVersion'
GO